package homework.five.S_5_1;

import java.util.Scanner;

public class Demo {
    public static void main(String[] args) {
        TestList testList = new TestList();
        Scanner scanner = new Scanner(System.in);

        // 初始化测试数据
        testList.addEmp(new Emp("1001", "张一伟", 28));
        testList.addEmp(new Emp("1002", "王二芳", 32));
        testList.addEmp(new Emp("1003", "李三强", 25));

        while (true) {
            showMenu();
            int choice = scanner.nextInt();
            scanner.nextLine();

            switch (choice) {
                case 0:
                    System.out.println("系统已退出");
                    scanner.close();
                    return;
                case 1:
                    addEmployee(testList, scanner);
                    break;
                case 2:
                    testList.findAllEmp();
                    break;
                case 3:
                    searchByName(testList, scanner);
                    break;
                case 4:
                    deleteEmployee(testList, scanner);
                    break;
                case 5:
                    searchByNumber(testList, scanner);
                    break;
                case 6:
                    updateAge(testList, scanner);
                    break;
                default:
                    System.out.println("无效输入，请重新选择");
            }
        }
    }

    private static void showMenu() {
        System.out.println("0. 退出系统");
        System.out.println("1. 添加员工");
        System.out.println("2. 显示所有员工");
        System.out.println("3. 按姓名查询");
        System.out.println("4. 按编号删除");
        System.out.println("5. 按编号查询");
        System.out.println("6. 修改年龄");

    }

    private static void addEmployee(TestList testList, Scanner scanner) {
        System.out.print("请输入员工编号: ");
        String number = scanner.nextLine();
        System.out.print("请输入员工姓名: ");
        String name = scanner.nextLine();
        System.out.print("请输入员工年龄: ");
        int age = scanner.nextInt();
        scanner.nextLine();

        testList.addEmp(new Emp(number, name, age));
    }

    private static void searchByName(TestList testList, Scanner scanner) {
        System.out.print("请输入查询姓名: ");
        testList.findEmpByName(scanner.nextLine());
    }

    private static void deleteEmployee(TestList testList, Scanner scanner) {
        System.out.print("请输入删除编号: ");
        testList.deleteEmpByNumber(scanner.nextLine());
    }

    private static void searchByNumber(TestList testList, Scanner scanner) {
        System.out.print("请输入查询编号: ");
        testList.findEmpByNumber(scanner.nextLine());
    }

    private static void updateAge(TestList testList, Scanner scanner) {
        System.out.print("请输入员工编号: ");
        String number = scanner.nextLine();
        System.out.print("请输入新年龄: ");
        int age = scanner.nextInt();
        scanner.nextLine();
        testList.updateEmpAge(number, age);
    }
}
